package parser;

import java.util.ArrayList;
import java.util.List;

public class CFGNode {

	private String methodName, className, mvc;
	private String code;
	private List<CFGNode> comingNodes;
	private List<CFGNode> outgoingNodes;
	private String type;
	
	public CFGNode()
	{
		comingNodes = new ArrayList<CFGNode>();
		outgoingNodes = new ArrayList<CFGNode>();
	}
	
	public String getMethodName() {
		return methodName;
	}
	
	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}
	
	public String getClassName() {
		return className;
	}
	
	public void setClassName(String className) {
		this.className = className;
	}
	
	public String getMvc() {
		return mvc;
	}
	
	public void setMvc(String mvc) {
		this.mvc = mvc;
	}
	
	public String getCode() {
		return code;
	}
	
	public void setCode(String code) {
		this.code = code;
	}
	
	public void addComingNodes(CFGNode node)
	{
		boolean exist = false;
		
		if(comingNodes!=null)
		{
			for (CFGNode coming : comingNodes) 
			{
				if(coming.getClassName().equals(node.getClassName()) && coming.getMethodName().equals(node.getMethodName()) 
						&& coming.getMvc().equals(node.getMvc()) && coming.getCode().equals(node.getCode()))
				{
					exist=true;
					break;
				}
				
			}
		}
		if(comingNodes==null || !exist) comingNodes.add(node);
		
	}
	
	public void addOutgoingNodes(CFGNode node)
	{
		boolean exist = false;
		
		if(outgoingNodes!=null)
		{
			for(CFGNode outgoing : outgoingNodes)
			{
				if(outgoing.getClassName().equals(node.getClassName()) && outgoing.getMethodName().equals(node.getMethodName()) 
						&& outgoing.getMvc().equals(node.getMvc()) && outgoing.getCode().equals(node.getCode()))
				{
					exist=true;
					break;
				}
			}
		}
		if(outgoingNodes==null || !exist) outgoingNodes.add(node);
	}
	
	public List<CFGNode> getComingNodes() {
		return comingNodes;
	}

	public void setEntryNodes(List<CFGNode> comingNodes) {
		this.comingNodes = comingNodes;
	}

	public List<CFGNode> getOutgoingNodes() {
		return outgoingNodes;
	}

	public void setExitNodes(List<CFGNode> outgoingNodes) {
		this.outgoingNodes = outgoingNodes;
	}
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
}
